import React, {Component}  from "react"
import { v4 as uuidv4 } from 'uuid';
import './index.css'

export default class Add extends Component {
    // 添加事项
    addFun = (e) => {
        if(e.keyCode !== 13) return
        console.log('添加的事项：', e.target.value)
        let todoObj = {
            id: uuidv4(),
            name: e.target.value,
            done: false
        }
        this.props.addTodo(todoObj)
        e.target.value = ''
    }
    render() {
        return (
            <input
                className="todo-input common-border"
                type="text"
                placeholder="请输入待办项，按Enter键添加"
                onKeyUp={this.addFun}
            />
        )
    }
}